package com.csdj.server.controller;


import com.csdj.server.pojo.RespBean;
import com.csdj.server.pojo.Salary;
import com.csdj.server.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZouLi
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/salary/sob")
@Api(tags = "工资套账控制器")
public class SalaryController {

    /**
     * SalaryService
     **/
    @Autowired
    private ISalaryService salaryServiceImpl;

    @ApiOperation(value = "获取全部工资套账")
    @GetMapping("/getAllSalary")
    public List<Salary> getAllSalary(){
        return salaryServiceImpl.list();
    }

    @ApiOperation(value = "添加工资套账")
    @PostMapping("/saveSalary")
    public RespBean saveSalary(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if (salaryServiceImpl.save(salary)) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @ApiOperation(value = "修改工资套账信息")
    @PutMapping("/updateSalary")
    public RespBean updateSalary(@RequestBody Salary salary){
        if (salaryServiceImpl.updateById(salary)) {
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @ApiOperation(value = "删除工资套账")
    @DeleteMapping("/deleteSalary/{id}")
    public RespBean deleteSalary(@PathVariable Integer id){
        if (salaryServiceImpl.removeById(id)) {
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

}
